package conexao;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	
	private static final SessionFactory sessionFactory = buildSessionFactory();
	
	private static SessionFactory buildSessionFactory(){
		try {
			AnnotationConfiguration cfg = new AnnotationConfiguration().configure();
			return cfg.buildSessionFactory();
		} catch (Exception e) {
			System.out.println("Criacao inicial do objeto sessionFactory falhou"+e);
			throw new ExceptionInInitializerError(e);
		}

	}
	
	public static SessionFactory getSessionFactory(){
		return sessionFactory;
	}
}
